package com.hnjfzn.message.sms.domain.bo;

import com.alibaba.fastjson2.JSONObject;
import com.hnjfzn.common.core.exception.ServiceException;
import com.hnjfzn.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SmsParams {
    private String phone;
    private String content;
    private String sign;
    private String code;
    private Map<String, String> data;

    public String message() {
        if (StringUtils.isNotEmpty(this.getCode()) && null != this.getData() && !this.data.isEmpty()) {
            return JSONObject.toJSONString(this.getData());
        }
        if (StringUtils.isNotEmpty(this.getContent())) {
            return "【" + this.getSign() + "】" + this.getContent();
        }
        throw new ServiceException("解析短信内容异常");
    }
}
